{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01ec2ed9",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2025-05-14 14:35:19,701 - imgdown - INFO - SEP_PATTERN: \\s+|>\n"
     ]
    }
   ],
   "source": [
    "import imgdown\n",
    "import filenamehandler\n",
    "import requests\n",
    "import magic\n",
    "d=imgdown.ImageDownloader()\n",
    "fnh=filenamehandler.FilenameHandler()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ab47e3c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "url=r\"https://target.scene7.com/is/image/Target/GUEST_6c8cad53-1980-4e8f-ab19-6730ff673ac0\"\n",
    "url2=r\"https://medias.yves-rocher.fr/medias/?context=bWFzdGVyfGltYWdlc3w0ODAxN3xpbWFnZS9qcGVnfHN5c19tYXN0ZXIvaW1hZ2VzL2gzMC9oYTgvOTg2NTM5MzM0MDQ0NnxjNDY5Zjc2OTdhMDkyODc0OGRkNjVjNDUwNWNmYmFiMWQ2NWQxZjlhMzFkNzg0NGJmMWQ1N2I2MWE5MzBmNzcw&twic=v1/resize=1200/background=white\"\n",
    "# fh.get_file_extension_from_response_magic(url)\n",
    "res=requests.get(url)\n",
    "res.headers\n",
    "res2=requests.get(url2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eaa746b9",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2025-05-14 14:35:36,422 [WARNING] get_file_extension_from_response_magic: 同时提供了url和response参数，将优先使用response进行计算\n",
      "2025-05-14 14:35:36,422 [DEBUG] extract_chunk_from_response: 无法从 response.raw 读取数据：seek\n",
      "2025-05-14 14:35:36,423 [DEBUG] extract_chunk_from_response: response.raw 不可用，尝试从 response.content 获取数据\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'.jpg'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fnh.get_file_extension_from_response_magic(url2,response=res2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ecaf8154",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2025-05-14 14:35:31,005 [DEBUG] get_file_extension_from_response_magic: 尝试发送请求获取Response并读取前2KB数据来判断文件类型\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'.jpg'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fnh.get_file_extension_from_response_magic(url2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7882a49f",
   "metadata": {},
   "outputs": [],
   "source": [
    "fnh.get_file_mimetype_from_url_by_magic(url2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c4b04349",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(\"hello world\")\n",
    "fnh.get_file_extension_from_response_magic(response=res)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
